<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
		<link rel="stylesheet" href="../../css/public.css" media="all">
		<style>
			body {
				background-color: #ffffff;
			}
			/*表头居中、高和行高的设置*/
			.commodityBatchInfo>div>table+div div table tr th div {
				text-align: center;
				padding: 0px;
			}
			/*表体字体大小 、居中、高和行高的设置*/
			.commodityBatchInfo>div>table+div div table tr td div {
				text-align: center;
				padding: 0px;
			}

			/*表头居中、高和行高的设置*/
			#articleRepertoire+div div table tr th div {
				text-align: center;
				padding: 0px;
			}
			/*表体字体大小 、居中、高和行高的设置*/
			#articleRepertoire+div div table tr td div {
				text-align: center;
				padding: 0px;
			}

			/*表头居中、高和行高的设置*/
			#articleSurface+div div table tr th div {
				text-align: center;
				padding: 0px;
			}
			/*表体字体大小 、居中、高和行高的设置*/
			#articleSurface+div div table tr td div {
				text-align: center;
				padding: 0px;
			}

			/*表头居中、高和行高的设置*/
			#chooseArticle+div div table tr th div {
				text-align: center;
				padding: 0px;
			}
			/*表体字体大小 、居中、高和行高的设置*/
			#chooseArticle+div div table tr td div {
				text-align: center;
				padding: 0px;
			}
		</style>
	</head>

	<body>
		<!--库存调拨商品列表模块-->
		<div style="display: flex; justify-content: space-around;">
			<fieldset class="layui-inline table-search-fieldset" style="margin:0px; padding:10px 0px 0px 0px; height:480px;">
				<legend style="margin-left: 15px;">查询商品列表</legend>

				<form class="layui-form layui-inline">
					<div class="layui-input-inline">
						<div style="height:30px; text-indent:1em;">请输入商品编号或名称查询商品,查询到商品后添加到右边所选商品</div>
						<label class="layui-form-lable" style="margin-left:30px;">输入商品编号或名称查询</label>
						<div class="layui-input-inline" style="margin: 0px 20px 0px 5px;">
							<input type="text" id="proIdAndproName" class="layui-input" autocomplete="off" maxlength="10"/>
						</div>
					</div>
				</form>

				<button class="layui-btn layui-btn-radius layui-btn-normal" style="margin-top: 30px;" id="selectedItemBtn">加入所选商品</button>

				<!--查询商品列表-->
				<div class="layui-tab">
					<ul class="layui-tab-title" id="commodityList">
						<li class="layui-this">商品清单</li>
						<li>商品列表</li>
					</ul>
					<div class="layui-tab-content" style="width:566px; padding:0px 10px;">
						<!-- 商品清单容器 -->
						<div class="layui-tab-item layui-show">
							<div>
								<!--商品清单-->
								<table class="layui-hide" id="articleRepertoire" lay-filter="articleRepertoireFilter"></table>
							</div>
						</div>
						<!-- 商品列表容器 -->
						<div class="layui-tab-item">
							<div class="layui-inline" style="width: 160px;margin: 0px 15px 0px 10px;">
								<div id="proListTree" style="border:1px solid #eee;height:295px;overflow:auto;"></div>
							</div>
							<div class="layui-inline" style="width: 365px;">
								<!--商品列表-->
								<table class="layui-hide" id="articleSurface" lay-filter="articleSurfaceFilter"></table>
							</div>
						</div>
					</div>
				</div>
			</fieldset>

			<!--所选商品模块-->
			<div class="layui-inline">
				<fieldset class="table-search-fieldset" style="margin:0px;height:480px;padding:10px 10px 0px;">
					<legend style="margin-left: 15px;">所选商品</legend>

					<div class="layui-tab-item layui-show">
						<div style="width: 618px;">
							<!--所选商品-->
							<table class="layui-hide" id="chooseArticle" lay-filter="chooseArticleFilter"></table>
						</div>
					</div>

					<div class="selectedItembtn">
						<button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm">修改</button>
						<button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm">删除</button>
						<button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm">确认</button>
						<button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm">取消</button>
					</div>
				</fieldset>
			</div>
		</div>

		<!--增加商品（库存调拨）弹窗-->
		<div id="commodityInformationPopup" style="padding:0px 5px; display: none;">
			<form class="layui-form" lay-filter="InformationPopup">
				<fieldset class="table-search-fieldset" style="width: 580px;">
					<legend style="margin-left: 15px;">查询商品列表</legend>

					<div class="layui-inline" style="width:250px;margin-left:70px;">
						<div>
							<span>商品编号：</span>
							<input type="text" name="proId" class="layui-input-inline" readonly style="border:none; width:170px;margin-bottom:2px"/>
						</div>
						<div>
							<span>规格型号：</span>
							<input type="text" name="inveDescSize" class="layui-input-inline" readonly style="border:none; width:170px;margin-bottom:5px"/>
						</div>
						<div>
							<span>当前库存：</span>
							<input type="text" id="inveDescInventoryNum" name="inveDescInventoryNum" class="layui-input-inline" readonly style="border:none; width:170px;margin-bottom:1px"/>
						</div>
						<div>
							<span>生产厂商：</span>
							<input type="text" name="inveDescManufacturer" class="layui-input-inline" readonly style="border:none; width:170px;margin-bottom:5px"/>
						</div>
					</div>

					<div class="layui-inline">
						<div>
							<span>商品名称：</span>
							<input type="text" name="inveDescName" class="layui-input-inline" readonly style="border:none; width:180px;margin-bottom:5px"/></div>
						<div>
							<span style="margin-left:28px;">单位：</span>
							<input type="text" name="inveDescUnit" class="layui-input-inline" readonly style="border:none;width:120px;margin-bottom:5px"/>
						</div>
						<div>
							<span>批注文号：</span>
							<input type="text" name="inveDescPostil" class="layui-input-inline" readonly style="border:none;width:120px;margin-bottom:5px"/></div>
						<div>
							<span style="margin:0px 0px 0px 14px;">保质期：</span>
							<input type="text" id="quality" class="layui-input-inline" readonly style="border:none;width:120px;"/>
						</div>
					</div>
					<hr/>

					<div class="layui-inline">
						<div>
							<label class="layui-form-lable" style="margin-left: 100px;">数量:</label>
							<div class="layui-input-inline">
								<input type="number" name="inveDescNum" id="number" style="height:20px; width:100px;" value="1" min="1"/>
							</div>

							<label class="layui-form-lable" style="margin-left:80px;">产品批次:</label>
							<div class="layui-input-inline">
								<input type="text" name="inveDescBatchNum" id="inveDescBatchNum" class="layui-input-inline"
									   readonly style="height:20px; width:100px;text-indent:10px; border:none;"/>
							</div>
						</div>

						<div class="layui-inline" style="margin: 10px 0px 10px 70px;">
							<span>生产日期：</span><input type="text" name="inveDescStartDate" id="inveDescStartDate" class="layui-input-inline" readonly style="border:none; width:120px;margin-bottom:2px"/>
						</div>

						<div class="layui-inline" style="margin: 10px 0px 10px 72px;">
							<span>有效期：</span><input type="text" name="inveDescValidityDate" id="inveDescValidityDate" class="layui-input-inline" readonly
													style="border:none; width:120px;margin-bottom:2px;text-indent:5px;"/>
						</div>
					</div>
				</fieldset>

				<div class="confirmCancelButton" style="text-align:center;">
					<button type="button" class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm" style="margin: 10px 150px 0px 0px;">确认</button>
					<button type="button" class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm" style="margin-top: 10px;">取消</button>
				</div>

				<div>
					<span>商品批次信息</span>
					<fieldset class="table-search-fieldset commodityBatchInfo" style="width:577px; padding:0px 2px;">
						<legend style="margin-left: 15px;">可以在下面列表中选择不同批次的商品</legend>

						<div class="layui-tab-item layui-show">
							<!--商品批次信息-->
							<table class="layui-hide" id="commodityBatch" lay-filter="commodityBatchInfoFilter"></table>
						</div>
					</fieldset>
				</div>

				<!--隐藏的所需信息-->
				<div class="layui-inline" style="display:none;">
					<input type="text" name="inveDescPrice" id="inveDescPrice" class="layui-input-inline" readonly />
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="totalMoney" id="totalMoney" class="layui-input-inline" readonly/>
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="inveDescType" id="inveDescType" class="layui-input-inline" readonly/>
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="inveDescPostil" id="inveDescPostil" class="layui-input-inline" readonly/>
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="inveDescProState" id="inveDescProState" class="layui-input-inline" readonly/>
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="inveDescComment" id="inveDescComment" class="layui-input-inline" readonly/>
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="supId" id="supId" class="layui-input-inline" readonly/>
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="inveDescDepot" id="inveDescDepot" class="layui-input-inline" readonly/>
				</div>
			</form>
		</div>

		<!--所选商品的取消按钮的弹窗-->
		<div id="selectedItemCancel" style="display:none;">
			<div style="text-align:center;margin: 40px 0px 40px 0px">所选商品还未保存，是否保存?</div>
			<div style="text-align: center;">
				<button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm">是</button>
				<button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm">否</button>
			</div>
		</div>

		<!--所选商品的删除按钮的弹窗-->
		<div id="whetherDelete" style="display:none;">
			<div style="text-align:center;margin: 40px 0px 40px 0px">是否删除该商品信息？</div>
			<div style="text-align: center;">
				<button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm">是</button>
				<button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm">否</button>
			</div>
		</div>

		<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
		<script>
            /*临时存放要交互的数据*/
            var temporaryStorageArray = [];
			layui.use(['form', 'table','tree'], function() {
				var form = layui.form,
					layer = layui.layer,
					$ = layui.$,
					tree = layui.tree;
				var table = layui.table;

				/*商品清单点击查询出来的数据 临时存放的变量名*/
                var row;
				/*商品信息（库存调拨）弹窗退出按钮时用的变量名*/
                var index;
                /*区分在那里按的确认按钮*/
                var affirm;
                /*获取表的index*/
                var surfaceIndex = 0;
                /*调拨数量*/
                var number;
                /*库存数量*/
                var stockNumber;
                /*商品Id或名称*/
				var proIdAndproName;
				/*商品Id*/
				var proId;


                /*商品信息（库存调拨）弹窗*/
                function addhotd(data) {
                   index = layer.open({
                        type: 1,
                        title: '商品信息(库存调拨)',
                        content: $('#commodityInformationPopup'),
                        area: ["600px", "560px"],
                        success:function () {
                            form.val('InformationPopup',data);
                        }
                    })
                };

                /*关闭商品信息（库存调拨）弹窗*/
                function exit() {
                    layer.close(index);
                }

                /*判断调拨数量的范围*/
                $('#number').bind('input',function () {
                    var number = +$('#number').val();
					/*库存数量*/
                    stockNumber = +row.inveDescInventoryNum;
                    /*调拨数量不能小于一*/
                    if(number < 0){
                        $('#number').val(1);
                    }
                });

                /*点击商品信息（库存调拨）弹窗取消按钮*/
                $('.confirmCancelButton>button:nth-of-type(2)').click(function () {
					exit();
                    $('#number').val(1);
                });

                /*系统提示库存数量小于调拨数量*/
                var inventoryQuantityPrompt = function () {
                    layer.open({
                        type:0,
                        title:'系统提醒',
                        content:'库存数量小于调拨数量,不允许调拨!'
                    });
                }

                /*库存调拨弹窗变成修改窗*/
                var chooseArticleCentre = function () {
                    number = +$('#number').val();
                    stockNumber = +row.inveDescInventoryNum;
                    if(number == 0){
                        $('#number').val(1);
                        number = +$('#number').val();
                    }
                    if(number <= stockNumber){
                        exit();
                        $('#totalMoney').val(number * row.inveDescPrice);
                        /*获取需要用的数据*/
                        temporaryStorageArray[surfaceIndex] = form.val('InformationPopup');
                        chooseArticleSurface();
                    }else if(stockNumber == 0){
                        layer.open({
                            type:0,
                            title:'系统提醒',
                            content:'抱歉,该批次的商品已经销完了!'
                        });
                    }else{
                        inventoryQuantityPrompt();
                        $('#number').val(stockNumber);
					}
                };

                /*商品信息（库存调拨）弹窗确认选择商品批次信息的这行数据*//*VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV*/
				var confirmSelection = function () {
                    number = +$('#number').val();
                    stockNumber = +row.inveDescInventoryNum;
                    if(number == 0){
                        $('#number').val(1);
                        number = +$('#number').val();
                    }
                    /*商品是否已经存在所选商品表中*/
					var whetherExist = false;
                    for(var i = 0;i < temporaryStorageArray.length;i++){
						if(temporaryStorageArray[i].proId == row.proId  &&
							temporaryStorageArray[i].inveDescBatchNum == row.inveDescBatchNum &&
							temporaryStorageArray[i].inveDescPrice == row.inveDescPrice){
						    surfaceIndex = i;
                            whetherExist = true;
						}
					}

					if(whetherExist){
                        /*该商品已经存在本次调拨中 对该商品做修改操作*/
                        if(number <= stockNumber){
                            exit();
                            $('#totalMoney').val(number * row.inveDescPrice);
                            temporaryStorageArray[surfaceIndex] = form.val('InformationPopup');
                            chooseArticleSurface();
                        }else if(stockNumber == 0){
                            layer.open({
                                type:0,
                                title:'系统提醒',
                                content:'抱歉,该批次的商品已经销完了!'
                            });
                        }else{
                            inventoryQuantityPrompt();
                            $('#number').val(stockNumber);
                        }
					}else{
                        /*该商品不存本次调拨中 对该商品做新增操作*/
                        if(number <= stockNumber){
                            exit();
                            $('#totalMoney').val(number * row.inveDescPrice);
                            /*获取需要用的数据*/
                            var getInteractiveData = form.val('InformationPopup');
                            temporaryStorageArray.push(getInteractiveData);
                            chooseArticleSurface();
						}else if(stockNumber == 0){
                            layer.open({
                                type:0,
                                title:'系统提醒',
                                content:'抱歉,该批次的商品已经销完了!'
                            });
                        }else{
                            inventoryQuantityPrompt();
                            $('#number').val(stockNumber);
                        }
					}
                }

				/*点击商品信息（库存调拨）弹窗的确认按钮*/
                 $('.confirmCancelButton>button:nth-of-type(1)').click(function () {
                    if(affirm === "articleRepertoireCentre"){
                        confirmSelection();
					}else if(affirm === "chooseArticleCentre"){
                        chooseArticleCentre();
					}
                });



                /*商品清单所选列表添加样式*/
                /*加入商品条件输入框*/
				$('#proIdAndproName').bind('input',function () {
				    var commodityList = $('#commodityList .layui-this').html();
				    if("商品清单" === commodityList){
                        proIdAndproName  = $(this).val();
                        searchInventoryDescInfo();
					}
                });
                /*商品清单所选列表单击*/
                table.on('row(articleRepertoireFilter)', function(obj) {
                    $('#number').val(1);
                    obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
                    row = obj.data;
                    affirm = "articleRepertoireCentre";
                });
                /*加入所选商品按钮*/
                $('#selectedItemBtn').click(function() {
                    commodityBatchSurface();
                    addhotd(row);
                });
                /*商品清单所选列表双击*/
                table.on('rowDouble(articleRepertoireFilter)', function(obj){
					commodityBatchSurface();
                    addhotd(row);
                });
				/*商品清单*/
				var searchInventoryDescInfo = function () {
                    table.render({
                        elem: '#articleRepertoire',
                        url: '/searchInventoryDescInfo?proIdAndproName='+proIdAndproName+'&depotName='+parent.depotName,
                        height: '300',
                        defaultToolbar: ['filter', 'exports', 'print', {
                            title: '提示',
                            layEvent: 'LAYTABLE_TIPS',
                            icon: 'layui-icon-tips'
                        }],
                        cols: [
                            [{
                                field: 'proId',
                                width: 90,
                                title: '商品编号'
                            }, {
                                field: 'inveDescName',
                                width: 149,
                                title: '商品名称'
                            }, {
                                field: 'inveDescUnit',
                                width: 60,
                                title: '单位'
                            }, {
                                field: 'inveDescSize',
                                width: 60,
                                title: '规格'
                            }, {
                                field: 'inveDescInventoryNum',
                                title: '库存量',
                                width: 80
                            }, {
                                field: 'inveDescManufacturer',
                                width: 120,
                                title: '生产商'
                            }]
                        ],
                        done: function (obj) {
                            row = obj.data[0];
                            $('#articleRepertoire~div tr[data-index=0]').addClass('layui-bg-green');
                            affirm = "articleRepertoireCentre";
                        }
                    });
                }
                searchInventoryDescInfo();


                /*树形控件*/
                $.ajax({
                    url:'/showProductTypeInfo',
                    success:function (data) {
                        var treeData = JSON.parse(data);
                        tree.render({
                            elem: '#proListTree',
                            data: treeData,
                            click:function (obj) {
                                var typeId= obj.data.id;
                                var depotName = parent.depotName;
                                table.reload('articleSurface',{
                                    url:'/searchInventorDescInfoType/'+typeId+'/'+depotName
                                });
                                console.log(typeId);
                            }
                        })
                    }
                });
                /*商品列表单击效果*/
                table.on('row(articleSurfaceFilter)', function(obj) {
                    $('#number').val(1);
                    obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
                    row = obj.data;
                    affirm = "articleRepertoireCentre";
                });
                /*商品列表双击效果*/
                table.on('rowDouble(articleSurfaceFilter)', function(obj){
                    commodityBatchSurface();
                    addhotd(row);
                });
				/*商品列表*/
				table.render({
					elem: '#articleSurface',
					data: [],
					height: '300',
					defaultToolbar: ['filter', 'exports', 'print', {
						title: '提示',
						layEvent: 'LAYTABLE_TIPS',
						icon: 'layui-icon-tips'
					}],
					cols: [
						[{
							field: 'proId',
							width: 100,
							title: '商品编号'
						}, {
							field: 'inveDescName',
							width: 140,
							title: '商品名称'
						}, {
							field: 'inveDescUnit',
							width: 60,
							title: '单位'
						}, {
							field: 'inveDescSize',
							width: 60,
							title: '规格'
						}, {
                            field: 'inveDescInventoryNum',
                            title: '库存量',
                            width: 80
                        }, {
                            field: 'inveDescManufacturer',
                            width: 120,
                            title: '生产商'
                        }]
					],done: function (obj) {
                        row = obj.data[0];
                        $('#articleSurface~div tr[data-index=0]').addClass('layui-bg-green');
                        affirm = "articleRepertoireCentre";
                    }
				});



                /*所选商品所选列表添加样式*/
                /*所选商品所选列表单击*/
                table.on('row(chooseArticleFilter)', function(obj){
                    obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
                    row = obj.data;
                    surfaceIndex = obj.tr.attr('data-index');
                    affirm = "chooseArticleCentre";
                });
                /*所选商品所选列表双击*/
                table.on('rowDouble(chooseArticleFilter)', function(obj){
					addhotd(row);
					commodityBatchSurface();
                });

                /*所选商品的修改按钮*/
                $('.selectedItembtn>button:nth-of-type(1)').click(function () {
                    if(temporaryStorageArray.length > 0){
                        addhotd(row);
                        $("#inveDescStartDate").val(timeTransform(row.inveDescStartDate));
                        $("#inveDescValidityDate").val(timeTransform(row.inveDescValidityDate));
                        chooseArticleSurface();
                        affirm = "chooseArticleCentre";
					}
                });

                /*所选商品的删除按钮*/
				$('.selectedItembtn>button:nth-of-type(2)').click(function () {
                    index = layer.open({
                        type: 1,
                        title: '系统提示',
                        content: $('#whetherDelete'),
                        area: ["300px", "190px"]
                    });
                    var yesOrNo = function () {
                        /*是删除*/
                        $('#whetherDelete>div:nth-of-type(2)>button:nth-of-type(1)').click(function () {
                            exit();
                            temporaryStorageArray.splice(surfaceIndex,1);
                            table.reload('chooseArticle',{
                                data:temporaryStorageArray
                            });
                            this.unbind();
                            yesOrNo();
                        });
                        /*否 删除*/
                        $('#whetherDelete>div:nth-of-type(2)>button:nth-of-type(2)').click(function () {
                            exit();
                            this.unbind();
                            yesOrNo();
                        });
                    }
                    yesOrNo();

                });

				/*判断新增的数据 在调拨页面是否存在*//*VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV*/
				var saveInformation = function () {
                    for(var i = 0; i < temporaryStorageArray.length; i++){
                        if(parent.temporaryStorageArrays.length > 0){
                            var cunbucunzai = true;
                            for(var j = 0;j < parent.temporaryStorageArrays.length; j++){
                                if(temporaryStorageArray[i].inveDescBatchNum == parent.temporaryStorageArrays[j].inveDescBatchNum
                                    && temporaryStorageArray[i].proId == parent.temporaryStorageArrays[j].proId
									&& temporaryStorageArray[i].inveDescPrice == parent.temporaryStorageArrays[j].inveDescPrice){
                                    parent.temporaryStorageArrays[j] = temporaryStorageArray[i];
                                    cunbucunzai = false;
                                }
                            }
                            if(cunbucunzai){
                                parent.temporaryStorageArrays.push(temporaryStorageArray[i]);
                            }
                        }else{
                            parent.temporaryStorageArrays.push(temporaryStorageArray[i]);
                        }
                    }

                    parent.layui.table.reload('currentTableId',{
                        data:parent.temporaryStorageArrays
                    });

                    index = parent.layer.getFrameIndex (window.name);
                    parent.layer.close(index);

                    temporaryStorageArray = [];

                    /*给父窗口的元素赋值*/
                    $('#transferOutOfWarehouse',window.parent.document).attr("disabled",true);
                    /*表单刷新*/
                    parent.layui.form.render('select');

                    /*显示父窗口的删除和修改按钮*/
                    $('button[lay-event=deleteItem]',window.parent.document).css('display','inline-block');
                    $('button[lay-event=modifyProduct]',window.parent.document).css('display','inline-block');
                }
				/*所选按钮的确认按钮*/
				$('.selectedItembtn>button:nth-of-type(3)').click(function () {
				    if(temporaryStorageArray.length > 0){
                        saveInformation();
					}else{
                        layer.open({
                            type:0,
                            title:'系统提醒',
                            content:'请先选择商品!'
                        });
					}
                });

				/*所选商品的取消按钮*/
				$('.selectedItembtn>button:nth-of-type(4)').click(function () {
					/*不保存选择*/
					if(temporaryStorageArray.length>0){
                        layer.open({
                            type: 1,
                            title: '系统提示',
                            content: $('#selectedItemCancel'),
                            area: ["300px", "190px"]
                        });
                        $('#selectedItemCancel>div:nth-of-type(2)>button:nth-of-type(2)').click(function () {
                            index = parent.layer.getFrameIndex (window.name);
                            parent.layer.close(index);
                        });
                        $('#selectedItemCancel>div:nth-of-type(2)>button:nth-of-type(1)').click(function () {
                            saveInformation();
                        });
					}else{
                        index = parent.layer.getFrameIndex (window.name);
                        parent.layer.close(index);
					}
                });

				/*所选商品*/
				var chooseArticleSurface = function () {
                    table.render({
                        elem: '#chooseArticle',
                        data: temporaryStorageArray,
                        height: '400',
                        defaultToolbar: ['filter', 'exports', 'print', {
                            title: '提示',
                            layEvent: 'LAYTABLE_TIPS',
                            icon: 'layui-icon-tips'
                        }],
                        cols: [
                            [{
                                field: 'inveDescName',
                                width: 130,
                                title: '商品名称'
                            }, {
                                field: 'inveDescUnit',
                                width: 60,
                                title: '单位'
                            }, {
                                field: 'inveDescSize',
                                width: 60,
                                title: '规格'
                            }, {
                                field: 'inveDescNum',
                                width: 60,
                                title: '数量'
                            }, {
                                field: 'inveDescBatchNum',
                                title: '生产批号',
                                width: 100
                            }, {
                                field: 'inveDescStartDate',
                                width: 100,
                                title: '生产日期',
                                templet:function (data){return timeTransform(data.inveDescStartDate)}
                            }, {
                                field: 'inveDescValidityDate',
                                width: 100,
                                title: '有效日期',
                                templet:function (data){return timeTransform(data.inveDescValidityDate)}
                            }]
                        ],done: function (obj) {
                            row = obj.data[surfaceIndex];
							$('#chooseArticle~div tr[data-index='+surfaceIndex+']').addClass('layui-bg-green');
                        }
                    });
                }
                chooseArticleSurface();


                /*商品批次所选列表添加样式*/
                /*单击*//*VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV*/
                table.on('row(commodityBatchInfoFilter)', function(obj){
                    row = obj.data;
                    //surfaceIndex = 0;
                    obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
					$('#inveDescBatchNum').val(row.inveDescBatchNum);
					$('#inveDescValidityDate').val(timeTransform(row.inveDescValidityDate));
                    $('#inveDescStartDate').val(timeTransform(row.inveDescStartDate));
					$('#inveDescInventoryNum').val(row.inveDescInventoryNum);
					$('#inveDescPrice').val(row.inveDescPrice);

                    var quality  = parseInt((row.inveDescValidityDate - row.inveDescStartDate)/1000/60/60/24/30)+"个月";
                    $('#quality').val(quality);
                    /*form.val('InformationPopup',row);
                    commodityBatchSurface()*/
                    /*$('#inveDescValidityDate').val(timeTransform(row.inveDescValidityDate));
                    $('#inveDescStartDate').val(timeTransform(row.inveDescStartDate));*/

                });
                /*双击*/
                table.on('rowDouble(commodityBatchInfoFilter)', function(obj){
                    confirmSelection();
                });
                /*商品批次信息*/
                var commodityBatchSurface = function () {
                    table.render({
                        elem: '#commodityBatch',
                        url: '/searchCommodityBatch/'+row.proId+'/'+parent.depotName,
                        height: '180',
                        defaultToolbar: ['filter', 'exports', 'print', {
                            title: '提示',
                            layEvent: 'LAYTABLE_TIPS',
                            icon: 'layui-icon-tips'
                        }],
                        cols: [
                            [{
                                field: 'proId',
                                width: 81,
                                title: '商品编号'
                            }, {
                                field: 'inveDescName',
                                width: 81,
                                title: '商品名称'
                            }, {
                                field: 'purStoDate',
                                width: 81,
                                title: '进货日期',
                                templet:function (data){return timeTransform(data.purStoDate)}
                            }, {
                                field: 'inveDescInventoryNum',
                                width: 81,
                                title: '库存数量'
                            }, {
                                field: 'inveDescBatchNum',
                                title: '产品批次',
                                width: 81
                            }, {
                                field: 'inveDescStartDate',
                                width: 81,
                                title: '生产日期',
                                templet:function (data){
                                    $('#inveDescStartDate').val(timeTransform(data.inveDescStartDate));
                                    return timeTransform(data.inveDescStartDate)}
                            }, {
                                field: 'inveDescValidityDate',
                                width: 82,
                                title: '有效日期',
                                templet:function (data){
                                    $('#inveDescValidityDate').val(timeTransform(data.inveDescValidityDate));
                                    return timeTransform(data.inveDescValidityDate)}
                            }]
                        ],done: function (obj) {
                            var commodityBatchindex = 0;
                            for(var i = 0;i<obj.data.length; i++){
                                if(obj.data[i].inveDescBatchNum == row.inveDescBatchNum){
                                    row = obj.data[i];
                                    commodityBatchindex = i;
								}
							}
                            $('#inveDescValidityDate').val(timeTransform(obj.data[commodityBatchindex].inveDescValidityDate));
                            $('#inveDescStartDate').val(timeTransform(obj.data[commodityBatchindex].inveDescStartDate));
							$('#commodityBatch~div tr[data-index='+commodityBatchindex+']').addClass('layui-bg-green');

                        	var quality  = parseInt((obj.data[commodityBatchindex].inveDescValidityDate -
											obj.data[commodityBatchindex].inveDescStartDate)/1000/60/60/24/30)+"个月";
                        	$('#quality').val(quality);
                        }
                    });
                }

				//监听提交
				form.on('submit(saveBtn)', function(data) {
					var index = layer.alert(JSON.stringify(data.field), {
						title: '最终的提交信息'
					}, function() {

						// 关闭弹出层
						layer.close(index);

						var iframeIndex = parent.layer.getFrameIndex(window.name);
						parent.layer.close(iframeIndex);

					});
					return false;
				});

                /*日期格式转换*/
                function timeTransform(date) {
                    var date = new Date(date);
                    var year = date.getFullYear();
                    var moth = date.getMonth() + 1;
                    var day = date.getDate();
                    return year + "-" + moth + "-" + day;
                }

			});
		</script>
	</body>

</html>